<?php

namespace JLPay\Models\Trans\B2c;

use JLPay\Models\BaseRequest;
use JLPay\Models\Trans\Dto\GoodsDataDto;
use JLPay\Models\Trans\Dto\TerminalInfoDto;

/**
 * 微支付请求
 */
class MicroPayRequest extends BaseRequest
{
    public const API_URL = "/open/trans/micropay";
    
    protected string $mchId = "";  // 商户号
    protected string $termNo = "";  // 终端号
    protected string $payType = "";  // 支付类型
    protected string $outTradeNo = "";  // 商户订单号
    protected string $paymentValidTime = "";  // 支付有效期
    protected string $body = "";  // 商品描述
    protected string $attach = "";  // 附加数据
    protected string $totalFee = "";  // 订单金额
    protected string $authCode = "";  // 授权码
    protected string $limitPay = "";  // 限制支付
    protected string $isHirePurchase = "";  // 是否分期付款
    protected string $hirePurchaseNum = "";  // 分期期数
    protected string $hirePurchaseSellerPercent = "";  // 分期手续费率
    protected string $remark = "";  // 备注
    protected string $opUserId = "";  // 操作员ID
    protected string $opShopId = "";  // 操作员门店ID
    protected string $deviceInfo = "";  // 设备信息
    protected string $mchCreateIp = "";  // 商户创建IP
    protected string $longitude = "";  // 经度
    protected string $latitude = "";  // 纬度
    protected string $subAppid = "";  // 子商户appid
    protected string $goodsTag = "";  // 商品标记
    protected ?GoodsDataDto $goodsData = null;  // 商品详情
    protected ?TerminalInfoDto $terminalInfo = null;  // 终端信息

    /**
     * 构造函数
     */
    public function __construct()
    {
        // 不需要调用父类构造函数
    }

    // 基础信息 getter/setter
    public function setMchId(string $mchId): self { $this->mchId = $mchId; return $this; }
    public function getMchId(): string { return $this->mchId; }
    
    public function setTermNo(string $termNo): self { $this->termNo = $termNo; return $this; }
    public function getTermNo(): string { return $this->termNo; }
    
    public function setPayType(string $payType): self { $this->payType = $payType; return $this; }
    public function getPayType(): string { return $this->payType; }
    
    public function setOutTradeNo(string $outTradeNo): self { $this->outTradeNo = $outTradeNo; return $this; }
    public function getOutTradeNo(): string { return $this->outTradeNo; }
    
    public function setPaymentValidTime(string $paymentValidTime): self { $this->paymentValidTime = $paymentValidTime; return $this; }
    public function getPaymentValidTime(): string { return $this->paymentValidTime; }
    
    public function setBody(string $body): self { $this->body = $body; return $this; }
    public function getBody(): string { return $this->body; }
    
    public function setAttach(string $attach): self { $this->attach = $attach; return $this; }
    public function getAttach(): string { return $this->attach; }
    
    public function setTotalFee(string $totalFee): self { $this->totalFee = $totalFee; return $this; }
    public function getTotalFee(): string { return $this->totalFee; }
    
    public function setAuthCode(string $authCode): self { $this->authCode = $authCode; return $this; }
    public function getAuthCode(): string { return $this->authCode; }
    
    public function setLimitPay(string $limitPay): self { $this->limitPay = $limitPay; return $this; }
    public function getLimitPay(): string { return $this->limitPay; }
    
    public function setIsHirePurchase(string $isHirePurchase): self { $this->isHirePurchase = $isHirePurchase; return $this; }
    public function getIsHirePurchase(): string { return $this->isHirePurchase; }
    
    public function setHirePurchaseNum(string $hirePurchaseNum): self { $this->hirePurchaseNum = $hirePurchaseNum; return $this; }
    public function getHirePurchaseNum(): string { return $this->hirePurchaseNum; }
    
    public function setHirePurchaseSellerPercent(string $hirePurchaseSellerPercent): self { $this->hirePurchaseSellerPercent = $hirePurchaseSellerPercent; return $this; }
    public function getHirePurchaseSellerPercent(): string { return $this->hirePurchaseSellerPercent; }
    
    public function setRemark(string $remark): self { $this->remark = $remark; return $this; }
    public function getRemark(): string { return $this->remark; }
    
    public function setOpUserId(string $opUserId): self { $this->opUserId = $opUserId; return $this; }
    public function getOpUserId(): string { return $this->opUserId; }
    
    public function setOpShopId(string $opShopId): self { $this->opShopId = $opShopId; return $this; }
    public function getOpShopId(): string { return $this->opShopId; }
    
    public function setDeviceInfo(string $deviceInfo): self { $this->deviceInfo = $deviceInfo; return $this; }
    public function getDeviceInfo(): string { return $this->deviceInfo; }
    
    public function setMchCreateIp(string $mchCreateIp): self { $this->mchCreateIp = $mchCreateIp; return $this; }
    public function getMchCreateIp(): string { return $this->mchCreateIp; }
    
    public function setLongitude(string $longitude): self { $this->longitude = $longitude; return $this; }
    public function getLongitude(): string { return $this->longitude; }
    
    public function setLatitude(string $latitude): self { $this->latitude = $latitude; return $this; }
    public function getLatitude(): string { return $this->latitude; }
    
    public function setSubAppid(string $subAppid): self { $this->subAppid = $subAppid; return $this; }
    public function getSubAppid(): string { return $this->subAppid; }
    
    public function setGoodsTag(string $goodsTag): self { $this->goodsTag = $goodsTag; return $this; }
    public function getGoodsTag(): string { return $this->goodsTag; }
    
    public function setGoodsData(?GoodsDataDto $goodsData): self { $this->goodsData = $goodsData; return $this; }
    public function getGoodsData(): ?GoodsDataDto { return $this->goodsData; }
    
    public function setTerminalInfo(?TerminalInfoDto $terminalInfo): self { $this->terminalInfo = $terminalInfo; return $this; }
    public function getTerminalInfo(): ?TerminalInfoDto { return $this->terminalInfo; }

    /**
     * 转换为数组
     *
     * @return array
     */
    public function toArray(): array
    {
        $data = parent::toArray();
        
        // 基础信息
        if ($this->mchId) $data['mch_id'] = $this->mchId;
        if ($this->termNo) $data['term_no'] = $this->termNo;
        if ($this->payType) $data['pay_type'] = $this->payType;
        if ($this->outTradeNo) $data['out_trade_no'] = $this->outTradeNo;
        if ($this->paymentValidTime) $data['payment_valid_time'] = $this->paymentValidTime;
        if ($this->body) $data['body'] = $this->body;
        if ($this->attach) $data['attach'] = $this->attach;
        if ($this->totalFee) $data['total_fee'] = $this->totalFee;
        if ($this->authCode) $data['auth_code'] = $this->authCode;
        if ($this->limitPay) $data['limit_pay'] = $this->limitPay;
        if ($this->isHirePurchase) $data['is_hire_purchase'] = $this->isHirePurchase;
        if ($this->hirePurchaseNum) $data['hire_purchase_num'] = $this->hirePurchaseNum;
        if ($this->hirePurchaseSellerPercent) $data['hire_purchase_seller_percent'] = $this->hirePurchaseSellerPercent;
        if ($this->remark) $data['remark'] = $this->remark;
        if ($this->opUserId) $data['op_user_id'] = $this->opUserId;
        if ($this->opShopId) $data['op_shop_id'] = $this->opShopId;
        if ($this->deviceInfo) $data['device_info'] = $this->deviceInfo;
        if ($this->mchCreateIp) $data['mch_create_ip'] = $this->mchCreateIp;
        if ($this->longitude) $data['longitude'] = $this->longitude;
        if ($this->latitude) $data['latitude'] = $this->latitude;
        if ($this->subAppid) $data['sub_appid'] = $this->subAppid;
        if ($this->goodsTag) $data['goods_tag'] = $this->goodsTag;
        
        // 复杂对象
        if ($this->goodsData) $data['goods_data'] = $this->goodsData->toArray();
        if ($this->terminalInfo) $data['terminal_info'] = $this->terminalInfo->toArray();
        
        return $data;
    }
} 